package com.compass.doctor.ui.consultation.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutConsultationDetailsDoctorItemBinding
import com.compass.doctor.databinding.LayoutConsultationListDoctorItemBinding
import com.compass.doctor.databinding.LayoutRecommendationDoctorItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.saveAs
import com.compass.framework.ext.visible
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.manager.DictionariesManager
import com.compass.framework.model.Doctor
import com.compass.framework.utils.BigDecimalUtils

/**
 * Description： 参加会诊医生adapter
 * Date:2023/12/22 9:06
 * @param orderType 1-我发起的 2-我参与的
 * @param itemType  1、已加入列表的， 2、详情的   3、推荐的
 */
class ConsultationDoctorAdapter constructor(private var itemType: Int,private var orderType:Int=1) :
    BaseMultiItemAdapter<Doctor>() {

    private lateinit var onChatBottomClick: OnCustomButtonClick
    fun setBottomCallBack(onChatBottomClick: OnCustomButtonClick) {
        this.onChatBottomClick = onChatBottomClick
    }
    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }



    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: Doctor?,
        position: Int
    ) {
        if (item == null) return
       //1、已加入列表的， 2、详情的   3、推荐的
        when (holder.itemViewType) {
            2 -> {
                val binding = holder.binding.saveAs<LayoutConsultationDetailsDoctorItemBinding>()
                binding.tvDoctorName.text =item.doctorName
                binding.tvHospital.text=item.hospitalName
                binding.tvRank.text=item.positionName
                binding.tvPrice.text= BigDecimalUtils.divide(item.price)
                binding.tvDepartmentName.text = item.departmentName
                binding.imgDoctorHead.setUrlCircle(item.doctorAvatar)
                if (orderType==1){
                    binding.tvExpenseName.visible()
                    binding.tvPriceSymbol.visible()
                    binding.tvPrice.visible()
                }else{
                    binding.tvExpenseName.gone()
                    binding.tvPriceSymbol.gone()
                    binding.tvPrice.gone()
                }
                binding.tvStatus.text= DictionariesManager.getParticipationStatusValue(item.status.toString())
                if (position==getData().size-1) binding.viewLine.visibility= View.GONE else binding.viewLine.visibility= View.VISIBLE
            }

            3 -> {
                val binding = holder.binding.saveAs<LayoutRecommendationDoctorItemBinding>()
                binding.tvDoctorName.text = "潘金莲"
                binding.tvNumbers.text= String.format("%s 次会诊", position)
            }

            else -> {
                val binding = holder.binding.saveAs<LayoutConsultationListDoctorItemBinding>()
                binding.tvName.text =item.doctorName
                binding.ivHead.setUrlCircle(item.doctorAvatar)
                if (position==getData().size-1) binding.viewLine.visibility= View.GONE else binding.viewLine.visibility= View.VISIBLE
            }
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {

            2 -> {
                LayoutConsultationDetailsDoctorItemBinding.inflate(layoutInflater, parent, false)
            }

            3 -> {
                LayoutRecommendationDoctorItemBinding.inflate(layoutInflater, parent, false)
            }

            else -> {
                LayoutConsultationListDoctorItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}